const { defineConfig } = require('@vue/cli-service')
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
const UnoCSS = require('@unocss/webpack').default

console.table({
  '系统名称': process.env.VUE_APP_TITLE,
  '系统标识': process.env.VUE_APP_IDENTIFY,
  '系统环境': process.env.NODE_ENV,
  '系统版本': process.env.VUE_APP_VERSION,
})

// 条件编译
const jsConditionalCompileLoaderOptions = {
  ONLY_NANCHANG: process.env.VUE_APP_IDENTIFY === 'nanchang',
  NOT_NANCHANG: process.env.VUE_APP_IDENTIFY !== 'nanchang'
}

module.exports = defineConfig({
  // indexPath: process.env.VUE_APP_IDENTIFY === 'nanchang' ? 'index-nc.html' : 'index.html',
  publicPath: process.env.VUE_APP_PUBLIC_PATH,
  transpileDependencies: true,
  productionSourceMap: false,
  css: {
    extract: true,
  },
  configureWebpack: {
    plugins: [
      UnoCSS(),
      new NodePolyfillPlugin()
    ],
    optimization: {
      realContentHash: true
    }
  },
  chainWebpack: (config) => {
    config.module
      .rule('vue')
      .test(/\.vue$/)
      .use('js-conditional-compile-loader')
        .loader('js-conditional-compile-loader')
        .options({
          ...jsConditionalCompileLoaderOptions
        })
        .end();
    config.module
      .rule('js')
      .test(/\.js$/)
      .use('js-conditional-compile-loader')
        .loader('js-conditional-compile-loader')
        .options({
          ...jsConditionalCompileLoaderOptions
        })
        .end();
  },
  devServer: {
    port: 4000,
  }
})
